/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.koron.purpose.domain.JobsStaffTask;
import com.koron.purpose.domain.StaffWorks;

public interface JobsStaffTaskMapper {

	@Delete("delete from jobs_staff_task where jobs_staff_id=#{id}")
	int delete(@Param("id") String jobsStaffId);
	
	@Insert("<script>"
			+ "insert into jobs_staff_task(id,task_type_id,task_type_label,task_object_id,task_object_label,note,cycle_id,cycle_label,duties_id,jobs_staff_id,start_date,start) values"
			+ "<foreach collection ='beanList' item='item' index='index' separator =','>"
			+ "(#{item.id},#{item.taskTypeId},#{item.taskTypeLabel},#{item.taskObjectId},#{item.taskObjectLabel},#{item.note},#{item.cycleId},#{item.cycleLabel},#{item.dutiesId},#{item.jobsStaffId},#{item.startDate},#{item.start}) </foreach>"
			+ "</script>")
	int batchInsert(@Param("beanList") List<JobsStaffTask> list);
	
	@Select("select * from jobs_staff_task where jobs_staff_id=#{id}")
	List<JobsStaffTask> queryByTid(@Param("id") String jobsStaffId);
	
	@Select("select * from jobs_staff_task where start=1")
	List<JobsStaffTask> queryAll();
	
	@Select("<script>"
			+ "select a.staff_code,a.staff_name,a.jobs_id,a.jobs_name,b.id,b.task_type_id,b.task_type_label,"
			+ "b.task_object_id,b.task_object_label,b.note,b.cycle_id,b.cycle_label,b.start_date,b.start"
			+ " from jobs_staff a RIGHT JOIN jobs_staff_task b on a.id=b.jobs_staff_id "
			+ " where a.staff_name like #{name} and a.jobs_name like #{jobsName} "
			+ "<if test='taskTypeId!=null and !taskTypeId.isEmpty()'> and b.task_type_id=#{taskTypeId} </if>"
			+ "<if test='cycleId!=null and !cycleId.isEmpty()'> and b.cycle_id=#{cycleId} </if>"
			+ "ORDER BY a.staff_code"
			+ "<if test='start!=null and end!=null'> limit #{start},#{end}</if>"
			+ "</script>")
	List<StaffWorks> queryStaffTasks(@Param("name") String name,@Param("jobsName") String jobsName,@Param("taskTypeId") String taskTypeId,@Param("cycleId") String cycleId,@Param("start") Integer start,@Param("end") Integer end);
	
	@Select("<script>"
			+ "select count(*) from jobs_staff a RIGHT JOIN jobs_staff_task b on a.id=b.jobs_staff_id where a.staff_name like #{name} and a.jobs_name like #{jobsName} "
			+ "<if test='taskTypeId!=null and !taskTypeId.isEmpty()'> and b.task_type_id=#{taskTypeId} </if>"
			+ "<if test='cycleId!=null and !cycleId.isEmpty()'> and b.cycle_id=#{cycleId} </if>"
			+ "</script>")
	int queryStaffTasksCount(@Param("name") String name,@Param("jobsName") String jobsName,@Param("taskTypeId") String taskTypeId,@Param("cycleId") String cycleId);
	
}
